package game;

import java.util.Objects;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 三石
 * Date: 2022-06-02
 * Time: 23:20
 */
public class Game {
    public static void Guess1() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请看题目");
        System.out.println("串天猴，纵长宙。上海宝，伫钟后。（猜一字）");
        String s = "审";
        String yes="是";
        String no="否";
        int d = 5;
        while (d > 0) {
            String str2 = scan.nextLine();
            if (s.equals(str2)) {
                System.out.println("恭喜你，猜对了");
                break;
            } else {
                System.out.println("很遗憾，猜错了，请重新猜");
                d--;
                if (d == 0) {
                    System.out.println("您已连续3次猜错，游戏结束");
                    System.out.println("是否需要重新开始游戏？");
                    String str3 = scan.nextLine();
                    if(Objects.equals(str3, yes)){
                        System.out.println("重新开始");
                    }else if(Objects.equals(str3, no)){
                        System.out.println("退出游戏");

                    }
                    break;
                }
            }
        }
    }
    public static void Doclass() {
        int count = 3;
        while (count > 0) {
            System.out.println("三国演义的作者是谁？");
            System.out.println("A.罗贯中");
            System.out.println("B.吴承恩");
            System.out.println("C.施耐庵");
            System.out.println("D.曹雪芹");
            String answer = "A";

            Scanner scanner = new Scanner(System.in);
            String s = scanner.nextLine();
            if (Objects.equals(answer, s)) {
                System.out.println("恭喜你，回答正确！");
                break;
            } else {
                System.out.println("回答错误！请重新输入：");
                count--;
                if (count == 0) {
                    System.out.println("您已连续3次输入错误");
                    System.exit(0);
                }
            }
        }
    }
    public static void Guess(){
        Random rand=new Random(50);
        int randNum=rand.nextInt(50)+50;

        Scanner scan=new Scanner(System.in);
        System.out.println("请输入数字！");

        int d=3;  //有3次猜数字的机会
        while (d>0){
            int c=scan.nextInt();
            if(c>randNum){
                System.out.println("猜大了，请重新输入");
                d--;
            }else if(c<randNum){
                System.out.println("猜小了，请重新输入");
                d--;
            }
            else {
                System.out.println("恭喜你，猜对了");
                break;
            }
            if (d==0){
                System.out.println("您的3次机会已经全部用完，请重新开始");
            }
        }

    }


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        System.out.println("您是新用户，请先注册账号");
        System.out.println("请输入用户名：");
        String str = scan.nextLine();
        System.out.println("请设置密码：");
        String str1 = scan.nextLine();


        System.out.println("注册成功，请重新登录");
        int x = 0;

        int count = 3;
        while (count > 0) {
            System.out.println("请输入账号");
            String a = scan.nextLine();
            System.out.println("请输入密码");
            String b = scan.nextLine();

            if (Objects.equals(str, a) && Objects.equals(str1, b)) { //比较字符串的值，不能用==
                System.out.println("登录成功");
                x = 1;
                break;
            } else {
                System.out.println("账户或密码错误，请重新输入");
                count--;
                if (count == 0) {
                    System.out.println("您已连续3次输入错误，账号已被冻结");
                }
            }
        }
        if (x == 1) {
            do {
                System.out.println("===请选择菜单===");
                System.out.println("**1.猜数字***");
                System.out.println("**2.猜字谜***");
                System.out.println("**3.做练习***");
                System.out.println("**0.退出游戏**");
                int y = scan.nextInt();
                switch (y) {
                    case 1:
                        System.out.println("1.猜数字");
                        Guess();
                        break;
                    case 2:
                        System.out.println("2.猜字谜");
                        Guess1();
                        break;
                    case 3:
                        System.out.println("3.做练习");
                        Doclass();
                        break;
                    case 0:
                        System.out.println("退出游戏");
                        System.exit(0);
                        break;
                    default:
                        System.out.println("输入错误，请重新输入");
                }
            } while (true);
        }
    }
}
